package com.ruoyi.system.service.impl;

import java.io.File;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.utils.FileDataUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.GenerateRuleMapper;
import com.ruoyi.system.domain.GenerateRule;
import com.ruoyi.system.service.IGenerateRuleService;

/**
 * 生成规则Service业务层处理
 *
 * @author chenming
 * @date 2024-10-16
 */
@Service
public class GenerateRuleServiceImpl extends ServiceImpl<GenerateRuleMapper, GenerateRule> implements IGenerateRuleService
{
    @Autowired
    private GenerateRuleMapper generateRuleMapper;

    /**
     * 查询生成规则
     *
     * @param ruleId 生成规则主键
     * @return 生成规则
     */
    @Override
    public GenerateRule selectGenerateRuleByRuleId(Long ruleId)
    {
        return generateRuleMapper.selectGenerateRuleByRuleId(ruleId);
    }

    /**
     * 查询生成规则列表
     *
     * @param generateRule 生成规则
     * @return 生成规则
     */
    @Override
    public List<GenerateRule> selectGenerateRuleList(GenerateRule generateRule)
    {
        return generateRuleMapper.selectGenerateRuleList(generateRule);
    }

    /**
     * 新增生成规则
     *
     * @param generateRule 生成规则
     * @return 结果
     */
    @Override
    public int insertGenerateRule(GenerateRule generateRule)
    {
        int i = generateRuleMapper.insertGenerateRule(generateRule);
        return i;
    }

    /**
     * 修改生成规则
     *
     * @param generateRule 生成规则
     * @return 结果
     */
    @Override
    public int updateGenerateRule(GenerateRule generateRule)
    {
        int i = generateRuleMapper.updateGenerateRule(generateRule);
        // 更新模板
        FileDataUtils.removeFile(generateRule.getRuleName()+".py");
        return i;
    }

    /**
     * 批量删除生成规则
     *
     * @param ruleIds 需要删除的生成规则主键
     * @return 结果
     */
    @Override
    public int deleteGenerateRuleByRuleIds(Long[] ruleIds)
    {
        return generateRuleMapper.deleteGenerateRuleByRuleIds(ruleIds);
    }

    /**
     * 删除生成规则信息
     *
     * @param ruleId 生成规则主键
     * @return 结果
     */
    @Override
    public int deleteGenerateRuleByRuleId(Long ruleId)
    {
        return generateRuleMapper.deleteGenerateRuleByRuleId(ruleId);
    }
}
